package com.letoy.study.controller;

import com.letoy.study.entity.CourseInfo;
import com.letoy.study.service.CourseService;
import com.letoy.study.utils.FileUploadUtil;
import com.letoy.study.vo.CourseVo;
import com.letoy.study.vo.VideoUpload;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * @program:letoy-study-java
 * @author: WeiHaoL
 * @Time: 2021/1/25  下午3:16
 */

@RestController
public class CourseController {

    @Resource
    CourseService courseService;

    @PostMapping("/course/releaseCourse")
    @ApiOperation(value = "发布课程信息", notes = "发布课程信息")
    public HashMap<String, Object> releaseCourse(CourseVo courseVo){

        return courseService.releaseCourse(courseVo);
    }

    @PostMapping("/course/deleteCourse")
    @ApiOperation(value = "删除课程信息", notes = "删除课程信息")
    public HashMap<String,Object> deleteCourse(CourseInfo courseInfo){

        return courseService.deleteCourse(courseInfo);
    }

    @PostMapping("/course/findAllCourseInfo")
    @ApiOperation(value = "查询课程信息", notes = "查询课程信息")
    public HashMap<String,Object> findAllCourseInfo(String courseType){

        if (courseType != null) {
            return courseService.findAllCourseInfo(courseType);
        }
        return courseService.findAllCourseInfo();
    }

    @PostMapping("/course/videoUpload")
    @ApiOperation(value = "上传视频", notes = "上传视频")
    public HashMap<String,Object> videoUpload(@RequestPart MultipartFile file, long courseId){

        VideoUpload videoUpload = new VideoUpload(file, courseId);
        return courseService.videoUpload(videoUpload);
    }

}
